const http = require('http')
const fs = require('fs')
const path = require('path')
const app = http.createServer()
const qs = require('querystring')
app.on('request', (req, res) => {
    if (req.url == '/api/province') {
        fs.readFile(path.join(__dirname, 'province.json'), (err, data) => {
            // console.log(data.toString())
            res.end(data.toString())
        })
    } else if (req.url.split('?')[0] == '/api/city') {
        const data = qs.parse(req.url.split('?')[1])
        const { pname } = data
        fs.readFile(path.join(__dirname, 'city.json'), (err, data1) => {
            console.log(JSON.stringify(JSON.parse(data1.toString())[pname]))
            const data=JSON.stringify(JSON.parse(data1.toString())[pname])
            res.end(data)
        })
    }else{
        res.end('111')
    }

})
app.listen(54565, () => {
    console.log(111)
})